package pro1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import pro1.model.ResponseBody;
import pro1.service.ModuleService;

@RestController
@RequestMapping("module")
public class ModuleController {

	@Autowired
	ModuleService moduleService;

	/**
	 * 查询所有
	 * 
	 * @return
	 */
	@GetMapping("all")
	public ResponseBody all(@RequestParam(value = "chaId", required = false) Integer chaId) {

		return moduleService.all(chaId);
	}

	/**
	 * 添加或更新
	 * 
	 * @param depId
	 * @param name
	 * @param info
	 * @return
	 */
	@PostMapping("addOrUpdate")
	public ResponseBody addOrUpdate(@RequestParam(value = "id", required = false) Integer id,
			@RequestParam(value = "name", required = false) String name,
			@RequestParam(value = "path", required = false) String path,
			@RequestParam(value = "info", required = false) String info) {

		return moduleService.addOrUpdate(id, name, path, info);
	}

	/**
	 * 删除
	 * 
	 * @param depId
	 * @return
	 */
	@PostMapping("delete")
	public ResponseBody delete(@RequestParam(value = "id", required = true) Integer id) {

		return moduleService.delete(id);
	}
}
